home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-tasclo.adb < prev    next >
Text File  |  1996-01-30  |  5KB  |  170 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                     S Y S T E M . T A S K _ C L O C K                    --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.11 $                             --
  10. --                                                                          --
  11. --       Copyright (c) 1991,1992,1993,1994, FSU, All Rights Reserved        --
  12. --                                                                          --
  13. -- GNARL is free software; you can redistribute it  and/or modify it  under --
  14. -- terms  of  the  GNU  Library General Public License  as published by the --
  15. -- Free Software  Foundation;  either version 2, or (at  your  option)  any --
  16. -- later  version.  GNARL is distributed  in the hope that  it will be use- --
  17. -- ful, but but WITHOUT ANY WARRANTY;  without even the implied warranty of --
  18. -- MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. -- eral Library Public License  for more details.  You should have received --
  20. -- a  copy of the GNU Library General Public License along with GNARL;  see --
  21. -- file COPYING.LIB.  If not,  write to the  Free Software Foundation,  675 --
  22. -- Mass Ave, Cambridge, MA 02139, USA.                                      --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. package body System.Task_Clock is
  27.  
  28.    -----------------------
  29.    -- Stimespec_Seconds --
  30.    -----------------------
  31.  
  32.    function Stimespec_Seconds (TV : Stimespec) return Integer is
  33.    begin
  34.       return Integer (TV.Val / Stimespec_Sec_Unit.Val);
  35.    end Stimespec_Seconds;
  36.  
  37.    ------------------------
  38.    -- Stimespec_Nseconds --
  39.    -------------------------
  40.  
  41.    function Stimespec_NSeconds (TV : Stimespec) return Integer is
  42.    begin
  43.       return
  44.         Integer (TV.Val - Time_Base (Stimespec_Seconds (TV)) *
  45.           Stimespec_Sec_Unit.Val);
  46.    end Stimespec_NSeconds;
  47.  
  48.    -------------
  49.    -- Time_Of --
  50.    -------------
  51.  
  52.    function Time_Of (S, NS : Integer) return Stimespec is
  53.    begin
  54.       return Stimespec' (Val => Stimespec_Sec_Unit.Val * Time_Base (S) +
  55.         Time_Base (NS));
  56.    end Time_Of;
  57.  
  58.    ---------------------------
  59.    -- Stimespec_To_Duration --
  60.    ---------------------------
  61.  
  62.    function Stimespec_To_Duration (TV : Stimespec) return Duration is
  63.    begin
  64.       return Duration (long_float (TV.Val) / 10#1.0#E9);
  65.    end Stimespec_To_Duration;
  66.  
  67.    ---------------------------
  68.    -- Duration_To_Stimespec --
  69.    ---------------------------
  70.  
  71.    function Duration_To_Stimespec (Time : Duration) return Stimespec is
  72.    begin
  73.       return Stimespec' (Val => Time_Base (Time * 10#1.0#E9));
  74.    end Duration_To_Stimespec;
  75.  
  76.    ---------
  77.    -- "-" --
  78.    ---------
  79.  
  80.    --  Unary minus
  81.    function "-" (TV : Stimespec) return Stimespec is
  82.    begin
  83.       return Stimespec' (Val => -TV.Val);
  84.    end "-";
  85.  
  86.    ---------
  87.    -- "+" --
  88.    ---------
  89.  
  90.    function "+" (LTV, RTV : Stimespec) return Stimespec is
  91.    begin
  92.       return Stimespec' (Val => LTV.Val + RTV.Val);
  93.    end "+";
  94.  
  95.    ---------
  96.    -- "-" --
  97.    ---------
  98.  
  99.    function "-" (LTV, RTV : Stimespec) return Stimespec is
  100.    begin
  101.       return Stimespec' (Val => LTV.Val - RTV.Val);
  102.    end "-";
  103.  
  104.    ---------
  105.    -- "*" --
  106.    ---------
  107.  
  108.    function "*" (TV : Stimespec; N : Integer) return Stimespec is
  109.    begin
  110.       return Stimespec' (Val => TV.Val * Time_Base (N));
  111.    end "*";
  112.  
  113.    ---------
  114.    -- "/" --
  115.    ---------
  116.  
  117.    --  Integer division of Stimespec
  118.  
  119.    function "/" (TV : Stimespec; N : Integer) return Stimespec is
  120.    begin
  121.       return Stimespec' (Val => TV.Val / Time_Base (N));
  122.    end "/";
  123.  
  124.    ---------
  125.    -- "/" --
  126.    ---------
  127.  
  128.    function "/" (LTV, RTV : Stimespec) return Integer is
  129.    begin
  130.       return Integer (LTV.Val / RTV.Val);
  131.    end "/";
  132.  
  133.    ---------
  134.    -- "<" --
  135.    ---------
  136.  
  137.    function "<" (LTV, RTV : Stimespec) return Boolean is
  138.    begin
  139.       return LTV.Val < RTV.Val;
  140.    end "<";
  141.  
  142.    ----------
  143.    -- "<=" --
  144.    ----------
  145.  
  146.    function "<=" (LTV, RTV : Stimespec) return Boolean is
  147.    begin
  148.       return LTV.Val < RTV.Val or else RTV.Val = LTV.Val;
  149.    end "<=";
  150.  
  151.    ---------
  152.    -- ">" --
  153.    ---------
  154.  
  155.    function ">" (LTV, RTV : Stimespec) return Boolean is
  156.    begin
  157.       return RTV.Val < LTV.Val;
  158.    end ">";
  159.  
  160.    ----------
  161.    -- ">=" --
  162.    ----------
  163.  
  164.    function ">=" (LTV, RTV : Stimespec) return Boolean is
  165.    begin
  166.       return LTV.Val > RTV.Val or LTV.Val = RTV.Val;
  167.    end ">=";
  168.  
  169. end System.Task_Clock;
  170.